#include "cute.h"
#include "ide_listener.h"
#include "cute_runner.h"
#include "EnvironmentTest.h"

#include <physics>

namespace
{

using physics::RigidBody;
using physics::Triangle;
using physics::Square;
using physics::Pentagon;
using physics::Environment;

void ctor0Test()
{
	Environment e(25, 50, 5);
	ASSERT_EQUALM("Wrong width", 25, e.width());
	ASSERT_EQUALM("Wrong height", 50, e.height());
	ASSERT_EQUALM("Wrong gravity", 5, e.gravity());
}

void ctor1Test()
{
	RigidBody *s = new Square(4), *t = new Triangle(3), *p = new Pentagon(5);
	Environment e({t, s, p});
	ASSERT_EQUALM("Failed to add all shapes", 3, e.bodies().size());
	ASSERTM("Couldn't find triangle", e.bodies().count(t));
	ASSERTM("Couldn't find square", e.bodies().count(s));
	ASSERTM("Couldn't find pentagon", e.bodies().count(p));
}

void addBodyTest()
{
	Triangle *t1 = new Triangle(3), *t2 = new Triangle(5);
	Environment e;
	e.addBody(t1);
	ASSERT_EQUALM("Failed to add t1", 1, e.bodies().size());
	e.addBody(t2);
	ASSERT_EQUALM("Failed to add t2", 2, e.bodies().size());
	ASSERTM("Couldn't find t1", e.bodies().count(t1));
	ASSERTM("Couldn't find t2", e.bodies().count(t2));
}

void delBodyTest()
{
	RigidBody *s = new Square(4), *t = new Triangle(3), *p = new Pentagon(5);
	Environment e( {t, s, p});
	e.delBody(p);
	ASSERT_EQUALM("Failed to remove all shape", 2, e.bodies().size());
	ASSERTM("Still found pentagon", !e.bodies().count(p));
	ASSERTM("Couldn't find triangle", e.bodies().count(t));
	ASSERTM("Couldn't find square", e.bodies().count(s));
	delete p;
}
} // namespace

cute::suite make_suite_EnvironmentTest()
{
	cute::suite s;
	s.push_back(CUTE(ctor0Test));
	s.push_back(CUTE(ctor1Test));
	s.push_back(CUTE(addBodyTest));
	s.push_back(CUTE(delBodyTest));
	return s;
}

